﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using WP8DilbertCR.Resources;

namespace WP8DilbertCR
{
    public partial class MainPage : PhoneApplicationPage
    {
        public DateTime currentDate { get; set; }
        public MainPage()
        {
            InitializeComponent();

            ShowDate();
            BuildLocalizedApplicationBar();
        }

        private void ShowDate()
        {
            currentDate = DateTime.Now;
            titleText.Text = currentDate.ToShortDateString();
        }

        private void BuildLocalizedApplicationBar()
        {
            ApplicationBar = new ApplicationBar();

            // Create a new button and set the text value to the localized string from AppResources.
            ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/previous.png", UriKind.Relative));
            appBarButton.Text = AppResources.AppBarPrevButtonText;
            ApplicationBar.Buttons.Add(appBarButton);

            appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/random.png", UriKind.Relative));
            appBarButton.Text = AppResources.AppBarRandomButtonText;
            ApplicationBar.Buttons.Add(appBarButton);

            appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/pickadate.png", UriKind.Relative));
            appBarButton.Text = AppResources.AppBarPickButtonText;
            ApplicationBar.Buttons.Add(appBarButton);

            appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/next.png", UriKind.Relative));
            appBarButton.Text = AppResources.AppBarNextButtonText;
            ApplicationBar.Buttons.Add(appBarButton);

            // // Create a new menu item with the localized string from AppResources.
            // ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
            // ApplicationBar.MenuItems.Add(appBarMenuItem);
        }

        private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {
            if ((e.Orientation & PageOrientation.Portrait) == (PageOrientation.Portrait))
            {
                smallTitleText.Text = AppResources.ApplicationTitle;
                titleText.Visibility = System.Windows.Visibility.Visible;
                titleText.Text = currentDate.ToShortDateString();
            }
            else
            {
                smallTitleText.Text = currentDate.ToShortDateString();
                titleText.Visibility = System.Windows.Visibility.Collapsed;
            }
        }
    }
}